﻿<cfsilent>
	<cfscript>
		
		event.setArg("pageTitle", "毕业生管理 - 毕业资格审核 - 课程替代");
		
		markAdvice = getProperty("serviceFactory").getBean("markAdvice");
		
		studentId = event.getArg("STU");
		grade = event.getArg("GRD");
		subjectId = event.getArg("SBJ");
		courseId = event.getArg("CID");
		subjectDirection = event.getArg("SBJ_DIR");
		
		passArgs = structNew();
		
		structInsert(passArgs, "STU", studentId, true);
		structInsert(passArgs, "GRD", grade, true);
		structInsert(passArgs, "SBJ", subjectId, true);
		structInsert(passArgs, "CID", courseId, true);
		structInsert(passArgs, "SBJ_DIR", subjectDirection, true);
		
		/* 读取需要替换的课程 */
		sql = "SELECT course_name, cid, course_code FROM t_course  WHERE cid = :courseId ";
							
		queryObj = new Query( datasource=application.dnsSlave );
		queryObj.addParam( name="courseId", value=courseId, cfsqltype="cf_sql_varchar" );
		
		rs_course = queryObj.execute( sql=sql ).getResult();
		
		/* 读取通过课程 */
		
		sql = "	SELECT 
					b.cid, b.course_name, b.course_credit, b.course_code, a.credit_point 
				FROM 
					t_student_mark a 
					INNER JOIN t_course b ON b.cid = a.cid 
				WHERE 
					a.stu_id = :studentId 
					AND 
					a.credit_point > 0  
				ORDER BY 
					b.course_name ";

		queryObj = new Query( datasource=application.dnsSlave );

		queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" );
		queryObj.addParam( name="grade", value=grade, cfsqltype="cf_sql_char" );
		queryObj.addParam( name="subjectId", value=subjectId, cfsqltype="cf_sql_varchar" );
		queryObj.addParam( name="subjectDir", value=subjectId & subjectDirection, cfsqltype="cf_sql_varchar" );

		rs_pass = queryObj.execute( sql=sql ).getResult();

		/* 课程关键字成绩 */
		keywords = event.getArg("keywords");
		
		if( len (keywords) ){

			sql = "SELECT 
						b.cid, b.course_name, b.course_credit, b.course_code, a.credit_point 
					FROM 
						t_student_mark a 
						INNER JOIN t_course b ON b.cid = a.cid 
					WHERE 
						a.stu_id = :studentId 
						AND 
						a.credit_point > 0   
						AND
						(b.course_name LIKE :keywords OR b.course_code LIKE :keywords ) 
					ORDER BY 
						b.course_name ";
			
			
			queryObj = new Query( datasource=application.dnsSlave );
			
			queryObj.addParam( name="studentId", value=studentId, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="grade", value=grade, cfsqltype="cf_sql_char" );
			queryObj.addParam( name="subjectId", value=subjectId, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="subjectDir", value=subjectId & subjectDirection, cfsqltype="cf_sql_varchar" );
			queryObj.addParam( name="keywords", value='%' & keywords & '%', cfsqltype="cf_sql_varchar" );
				
			rs_pass = queryObj.execute( sql=sql ).getResult();
		
		}
		
		currentTab = event.getArg("TabID", "labSearch");
		
		targetCourseId = event.getArg("targetCourseId");
		
		rs_targetCourse = queryNew("cid");
		
		if( len(targetCourseId) ){
			
			currentTab = "labSetting";
			
			
			
			sql = "	SELECT *
					FROM query 
					WHERE 
						cid = :targetCourseId ";
					
			queryObj = new Query( dbtype="query" );
			queryObj.setAttributes( query=rs_pass );
			
			queryObj.addParam( name="targetCourseId", value=targetCourseId, cfsqltype="cf_sql_varchar" );
			
			rs_targetCourse = queryObj.execute( sql=sql ).getResult();
			
		}
		
	</cfscript>
</cfsilent>

<div id="headArea">
	<div class="uiHeader uiHeaderWithImage ptm">
		<div class="clearfix uiHeaderTop">
			<div class="uiHeaderActions rfloat">
				<a class="uiButton" href="<cfoutput>#buildURL('gradDegreeProfileView', passArgs)#</cfoutput>"><i class="mrs img btnPublish"></i><span class="uiButtonText">学生审核明细</span></a>
			</div>
			<div>
				<h2 class="uiHeaderTitle">
					<i class="uiHeaderImage img icon16x16 card"></i><cfoutput>#rs_course.course_name#</cfoutput> - 课程替代
				</h2>
			</div>
		</div>
	</div>
</div>

<div class="UIElement">
	<ul class="senateFirstPage">
		<li>
			<div class="clearfix" id="summary">
				
				
				<div class="UItab">
					<div class="tabLables">
						<span <cfif currentTab eq "labSearch">class="active"</cfif> id="labSearch" tabtarget="Search">指定替代课程</span>
						<cfif rs_targetCourse.recordCount>
							<span <cfif currentTab eq "labSetting">class="active"</cfif> id="labSetting" tabtarget="Setting">确认替代</span>
						</cfif>
					</div>
				</div>
				<script language="javascript" type="text/javascript">
					//<![CDATA[
					<!--
					$(document).ready(function() {
						
						/* init Tab */
						$("div.tabContent").hide();
						$("div#" + $("div.tabLables span.active").attr("tabTarget")).show();
						
						$("div.tabLables > span").click(function(){
							var $targetID = $(this).attr("tabTarget");
							
							$("div.tabLables span").removeClass("active");
							$(this).addClass("active");
							
							$("div.tabContent").not('[id="' + $targetID + '"]').hide();
							$("div.tabContent#" + $targetID).show();
						});
						
					});
					// -->
					//]]>
				</script>
				
				
				<div id="Search" class="tabContent" style="display: block;">
					
					<div class="noticeBlock">
						<h3>课程：<cfoutput>#rs_course.course_name#</cfoutput></h3>
						<p><span class="img icon16x16 message"></span>请选择以下通过课程做替代. </p>
						<hr/>
					</div>
					
					<form id="formSearch" onsubmit="javascript:return processVerfiyForm('formSearch');" class="formWrapper Transparent" method="post" action="<cfoutput>#BuildURL("signDegreeCourseReplace", passArgs)#</cfoutput>">
						<input type="hidden" name="TabID" value="labSearch">
						
						<div class="label">
							<b>课程</b>
							<input name="keywords" id="keywords" type="text" class="typeText" maxlength="128" value="">
						</div>
						<hr>
						<div class="lable">
							<input class="button1" type="submit" value="搜索">
						</div>
					</form>

					<table class="UIEditable">
						<thead>
							<tr>
								<td width="25"></td>
								<td width="50">课程名称</td>
								<td width="90">课程号</td>
								<td width="50">课程学分</td>
								<td width="50">操作</td>
							</tr>
						</thead>
						
						<tbody>
							<cfset row = 1 />
							<cfloop query="rs_pass">
								<cfset targetCourseId = rs_pass.cid />
								<cfset structInsert(passArgs, "targetCourseId", targetCourseId, true) />
								<tr class="editRows">
									<td class="index"><cfoutput>#row++#</cfoutput></td>
									<td><cfoutput>#rs_pass.course_name#</cfoutput></td>
									<td><span class="numeric"><cfoutput>#rs_pass.course_code#</cfoutput></span></td>
									<td><cfoutput>#rs_pass.course_credit#</cfoutput></td>
									<td><a title="替换" href="<cfoutput>#BuildURL("signDegreeCourseReplace", passArgs)#</cfoutput>" class="stat sign"></a></td>
								</tr>
							</cfloop>
						</tbody>
					</table>
					
				</div>
				
				
				<cfif rs_targetCourse.recordCount>
					<div id="Setting" class="tabContent" style="display: block;">
					
						<div class="noticeBlock">
							<h3><cfoutput>#rs_course.course_name#</cfoutput>(<cfoutput>#rs_course.course_code#</cfoutput>)即将被替代</h3>
							<p><span class="img icon16x16 message"></span>课程将由 <em><cfoutput>#rs_targetCourse.course_name#</cfoutput>(<cfoutput>#rs_targetCourse.course_code#</cfoutput>)</em> 替代, 请根据实际情况设置替代事项. </p>
							<hr>
						</div>
						
						<form id="formCondition" class="formWrapper " method="post" action="<cfoutput>#BuildURL("gradDegreeCourseReplace", passArgs)#</cfoutput>">
							<input type="hidden" name="CIDA" value="<cfoutput>#rs_course.cid#</cfoutput>"/>
							<input type="hidden" name="CIDB" value="<cfoutput>#rs_targetCourse.cid#</cfoutput>"/>
							
							<div class="label">
								<b>原课程</b>
								<div class="secondrow">
									<table>
										<tbody>
											<tr>
												<td><cfoutput>#rs_course.course_name#</cfoutput>(<cfoutput>#rs_course.course_code#</cfoutput>)</td>
											</tr>
										</tbody>
									</table>
								</div>
								
							</div>
							
							<div class="label">
								<b>替代课程</b>
								<div class="secondrow">
									<table>
										<tbody>
											<tr>
												<td><cfoutput>#rs_targetCourse.course_name#</cfoutput>(<cfoutput>#rs_targetCourse.course_code#</cfoutput>)</td>
											</tr>
										</tbody>
									</table>
								</div>
							</div>
							
							<div class="label">
								<b>可选项</b>
								<input name="isChecked" type="checkbox" class="typeCheckbox" value="1" >将课程替代应用到整个专业计划
							</div>
							
							<hr>
								
							<div class="lable">
								<input class="button" type="submit" value="确认替代">
							</div>
							
						</form>
					
					</div>
				</cfif>
			</div>
		</li>
	</ul>
</div>
